<?php
namespace Todo\Model\Sys;

class TokenModel extends SysBaseModel
{
    protected $_auto = array(
        array('is_expired', '0', self::MODEL_INSERT),
        array('scope', 'public', self::MODEL_INSERT),
        array('code', '_code', self::MODEL_INSERT, 'callback'),
        array('create_time', '_now', self::MODEL_INSERT, 'callback')
    );

    protected function _code()
    {
        if (!$this->code) $this->code = md5($this->user_id. $this->ip. NOW_TIME. rand(0,100000));
        return $this->code;
    }

    protected function _now(){
        return date('Y-m-d H:i:s');
    }
}